<template>
  <div class="calendar">
    <div class="title">
      <NuxtImg :src="assets.titleIcon" alt="VIP" />
      <p>{{ lang.title }}</p>
    </div>
    <div class="bouns cardBg">
      <p>
        <span>{{ lang.awaiting_redeem }}</span>
        {{ userStore.moneyUnit }}&nbsp;0,00
      </p>
      <p>
        <span>{{ lang.received }}</span>
        {{ userStore.moneyUnit }}&nbsp;0,00
      </p>
    </div>
    <div class="paginationBox">
      <p>{{ lang.view_pending_bonus }}</p>
      <span v-click-move @click="handleViewMore">{{ lang.view_more }}</span>
    </div>
    <!-- 轮播 -->
    <div class="calendarCarousel">
      <Swiper2 :items="slides" ref="swiper2Ref">
        <template #default="{ item }">
          <div class="bodyBox">
            <div
              class="pendingRewards_ul_li_no_data"
              :class="{ check: item.isToday }"
            >
              <div class="date">
                <div class="title_date">{{ item.title }}</div>
                <div class="txt">
                  <span>{{ userStore.moneyUnit }} 0,00</span>
                </div>
              </div>
              <div class="no_data">
                <p>{{ lang.no }}</p>
                <p>{{ lang.reward }}</p>
              </div>
              <div></div>
            </div>
          </div>
        </template>
      </Swiper2>
      <!-- 翻页箭头 -->
      <div class="arrowLeft arrow" v-click-move @click="swiper2Ref.prev()">
        <NuxtImg :src="assets.arrowLeft" alt="Prev" />
      </div>
      <div class="arrowRight arrow" v-click-move @click="swiper2Ref.next()">
        <NuxtImg :src="assets.arrowRight" alt="Next" />
      </div>
    </div>
    <div class="bottom" v-click-move @click="handleBottomClick">
      <p>
        <span>{{ lang.bonus_explanation }}</span>
        <NuxtImg :src="assets.arrowRightSmall" alt="More" />
      </p>
    </div>
  </div>
</template>

<script setup lang="ts">
const lang: any = getCurrentPageLang("activity/vip");
const userStore = useUserStore();
const emits = defineEmits(["changeVerShow"]);

interface SlideItem {
  key: string;
  title: string;
  isToday: boolean;
}

const assets = {
  titleIcon: "/images/activity/vip/vip_12.png",
  arrowRightSmall: "/images/layout/icon-jtLeft.png",
  arrowLeft: "/images/layout/icon-jtLeft.png",
  arrowRight: "/images/layout/icon-jtRight.png",
};

function buildSlides(): SlideItem[] {
  const result: SlideItem[] = [];
  const today = new Date();
  for (let i = -7; i <= 7; i++) {
    const d = new Date(
      today.getFullYear(),
      today.getMonth(),
      today.getDate() + i
    );
    const isToday = i === 0;
    const day = d.getDate();
    const monthShort = d.toLocaleString("pt-BR", { month: "short" });
    const title = isToday ? lang.today : `${day} ${monthShort}`;
    result.push({ key: d.toISOString(), title, isToday });
  }
  return result;
}

const slides = ref<SlideItem[]>(buildSlides());

const swiper2Ref = ref();

function handleBottomClick() {
  navigateTo({ name: "activity-vip-detail" });
}

function handleViewMore() {
  emits("changeVerShow", true);
}
</script>

<style scoped lang="scss">
.calendar {
  width: 100%;
  padding: 0.35rem 0.3rem;
  background: var(--theme-color4);
  border-radius: 0.3rem;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  box-sizing: border-box;
}
.title {
  display: flex;
  align-items: center;
  gap: 0.06rem;

  img {
    width: 0.7rem;
    height: 0.7rem;
    margin-right: 0.13rem;
  }

  p {
    font-size: var(--font-title2);
    color: var(--theme-neutral1);
  }
}

.cardBg {
  background: var(--theme-color9);
  border: 0.03rem solid var(--theme-color7);
  border-radius: 0.2rem;
}

.bouns {
  margin-top: 0.3rem;
  padding: 0.45rem 0.28rem;
  display: flex;
  justify-content: space-between;

  p {
    font-size: 0.32rem;
    color: var(--theme-dec4);

    &.check,
    span {
      color: var(--theme-neutral1);
    }
  }
}

.paginationBox {
  margin-top: 0.45rem;
  display: flex;
  align-items: center;
  justify-content: space-between;

  p {
    font-size: 0.38rem;
    color: var(--theme-neutral1);
  }

  span {
    color: var(--theme-dec4);
  }
}

.bottom {
  margin-top: 0.35rem;
  margin-bottom: 0.3rem;
  color: var(--theme-neutral1);

  p {
    display: flex;
    align-items: center;
    justify-content: center;

    span {
      font-size: 0.32rem;
      margin-right: 0.12rem;
    }

    img {
      width: 0.3rem;
      height: 0.3rem;
      transform: rotate(180deg);
    }
  }
}

.calendarCarousel {
  position: relative;
  border-radius: 0.2rem;
  margin-top: 0.5rem;
  padding: 0 1rem;
  min-height: 4.9rem;
}

.bodyBox {
  display: flex;
  justify-content: center;
  align-items: center;
  width: 3.9rem;
  height: 4.9rem;
  background: var(--theme-color3);
  border-radius: 0.2rem;
  .date {
    text-align: center;
    margin-bottom: 0.64rem;
  }
  .no_data {
    text-align: center;
    font-size: 0.32rem;
    font-weight: 400;
    color: var(--theme-neutral2);
    line-height: 0.34rem;
  }
  .title_date {
    margin-bottom: 0.65rem;
    font-size: 0.37rem;
    font-weight: 700;
    color: var(--theme-neutral1);
  }
  .txt {
    font-size: 0.32rem;
    font-weight: 500;
    color: var(--theme-dec4);
  }
}

.arrow {
  position: absolute;
  top: calc(50% - 0.8rem);
  width: 0.6rem;
  height: 1.6rem;
  background: var(--theme-neutral3);
  border-radius: 0.1rem;
  display: flex;
  justify-content: center;
  align-items: center;
  img {
    width: 0.37rem;
  }
}
.arrowLeft {
  left: 0;
}
.arrowRight {
  right: 0;
}
</style>
